package com.atguigu.connection;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.alibaba.druid.pool.DruidPooledConnection;
import org.junit.Test;

import javax.sql.DataSource;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

/**
 * @author admin
 */
public class DruidTest {

    @Test
    public void testConnection1() throws SQLException {
        DruidDataSource source = new DruidDataSource();

        source.setDriverClassName("com.mysql.jdbc.Driver");
        source.setUrl("jdbc:mysql:///atguigu_jdbc");
        source.setUsername("root");
        source.setPassword("123456");

        DruidPooledConnection connection = source.getConnection();
        System.out.println(connection);
    }

    @Test
    public void testConnection2() throws Exception {
        Properties properties = new Properties();
        InputStream inputStream = ClassLoader.getSystemClassLoader().getResourceAsStream("druid.properties");
        properties.load(inputStream);

        DataSource source = DruidDataSourceFactory.createDataSource(properties);

        Connection connection = source.getConnection();
        System.out.println(connection);
    }
}
